from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField

class Category(models.Model):
    cname = models.CharField(max_length=128,unique=True,verbose_name='类别名称')

    class Meta:
        db_table = 't_category'
        verbose_name_plural = '类别'

    def __str__(self):
        return  "%s"%self.cname

class Tags(models.Model):
    tname = models.CharField(max_length=32,unique=True,verbose_name='标签名称')

    class Meta:
        db_table = 't_tags'
        verbose_name_plural = '标签'

    def __str__(self):
        return  "%s"%self.tname

class Post(models.Model):
    title = models.CharField(max_length=128,unique=True)
    desc = RichTextUploadingField(config_name='my_config')
    content = RichTextUploadingField(config_name='my_config')
    created = models.DateField(auto_now=True)
    modified = models.DateField(auto_now=True)
    category = models.ForeignKey(Category,on_delete=models.CASCADE)
    tags = models.ManyToManyField(Tags)

    class Meta:
        db_table = 't_post'
        verbose_name_plural = '帖子'

    def __str__(self):
        return  "%s"%self.title